class ApplicationController < ActionController::Base

helper_method :current_user
before_filter :confirm_logged_in
before_filter :confirm_is_admin

private
def current_user
  @current_user ||= User.find(session[:user_id]) if session[:user_id]
end

def confirm_logged_in
  unless session[:user_id]
    flash[:notice] = "Du måste vara inloggad"
    redirect_to  :controller => "sessions", :action => "new"
    return false  ## Glöm inte detta!
  else
  return true
  end
end
def confirm_is_admin
  
  if !session[:user_id]
    redirect_to  root_path

  else
    user = User.find(session[:user_id])
    (user.nil?) ? redirect_to(root_path) : (redirect_to(root_path) unless user.admin?)
  end
end
end

